#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int N,score = 0;
    int step[100000];
    int choice;

    while(cin>>N)
    {
        for(int j=0;j<N;j++)
        {
            cin>>step[j];
        }
        
        for(int i=0;i<N;i++)
        {
            if (step[i] >= step[i+1])
            {
                choice = step[i];
                score = score + step[i];
                i++;
            }
            else 
            {
                choice = step[i+1];
                score = score + step[i+1];
                i = i+2;
            }
        }
            cout<<score<<endl;
    }
    return 0;
}
